
import java.awt.Toolkit;
import java.util.Vector;

import javax.swing.ImageIcon;

import resource.JarResources;

public class Resource {
    public static Resource resource = null;

    public Resource(String path) {
        this.path = path;
        resources = new Vector();
        resource_names = new Vector();
        jar = new JarResources(path);

    }

    public static ImageIcon getImageIcon(String fname) {
        byte ba[] = jar.getResource(fname);

        if (ba != null)
            return new ImageIcon(Toolkit.getDefaultToolkit().createImage(
                    jar.getResource(fname)));
        else
            return null;
    }

    public static void radd(String rname, String fname) {
        resource_names.add(rname);
        resources.add(getImageIcon(fname));

    }

    public static void load() {
        radd("zoomin", "zoomin.gif");

        radd("zoomout", "zoomout.gif");

        radd("new", "new.gif");

        radd("open", "open.gif");

        radd("save", "save.gif");

        radd("cut", "cut.gif");

        radd("copy", "copy.gif");

        radd("paste", "paste.gif");

        radd("delete", "delete.gif");

        radd("refresh", "refresh.gif");

        radd("undo", "undo.gif");

        radd("redo", "redo.gif");

        radd("default", "default.gif");

        radd("grab", "grab.gif");

        radd("grabc", "grabc.gif");

        radd("grabbing", "grabbing.gif");

        radd("grabbingc", "grabbingc.gif");

        radd("wire", "wire.gif");

        radd("maple", "maple.gif");

        radd("project", "project.gif");

        radd("component", "class.gif");

        radd("instance", "instance.gif");

        radd("componentsview", "componentsview.gif");

        radd("console", "console.gif");

        radd("circuitlab", "circuitlab.gif");

        radd("tilehorizontally", "tilehorizontally.gif");

        radd("tilevertically", "tilevertically.gif");

        radd("rotate", "rotate.gif");

        radd("refresh", "refresh.gif");

        radd("delete", "delete.gif");

        radd("print", "print.gif");

        radd("magnify", "magnify.gif");

        radd("console", "console.gif");

        radd("grid", "grid.gif");

        radd("bigger", "bigger.gif");

        radd("smaller", "smaller.gif");

        radd("text", "text.gif");

        radd("componentspanel", "componentspanel.gif");

        radd("component", "class.gif");

        radd("instance", "instance.gif");

        radd("upbutton", "upbutton.gif");

        radd("infobutton", "infobutton.gif");

        radd("smallproject", "small_project.gif");

        radd("smallopen", "small_open.gif");

        radd("smallopendisabled", "small_open_disabled.gif");

        radd("intro_page", "intro_page.PNG");

        radd("theme_page", "theme_page.PNG");

        radd("maple_page", "maple_page.PNG");

        radd("done_page", "done_page.PNG");

        radd("small_error", "small_error.GIF");

    }

    public static int indexof(String s) {

        for (int i = 0; i < resource_names.size(); i++) {
            String n = (String) resource_names.get(i);

            if (n == s)
                return i;
        }

        return -1;
    }

    public static ImageIcon getImage(int i) {
        ImageIcon ic = (ImageIcon) resources.get(i);

        return ic;
    }

    public static ImageIcon getIcon(String icon) {
        icon = icon.trim();

        int index = indexof(icon);

        if (index != -1) {
            return getImage(index);
        } else {
            return null;
        }

    }

    public static String path;
    public static Vector resources;
    public static Vector resource_names;
    public static JarResources jar;

}
